<template>
    <div class="layout-route">
        <div class="card card-search">
            <el-form :model="queryParams" ref="queryForm" v-show="showSearch" inline label-width="100px">
                <el-form-item label="SPU" prop="spu">
                    <el-input v-model.trim="queryParams.spu" placeholder="请输入spu" clearable style="width: 240px" />
                </el-form-item>
                <el-form-item label="店铺" prop="shop_id">
                    <el-select v-model="queryParams.shop_id" placeholder="请选择店铺" clearable size="small" style="width: 240px">
                        <el-option v-for="(dict, index) in dict.shopList" :key="index" :label="dict.shop_name" :value="dict.shop_id" />
                    </el-select>
                </el-form-item>
                <el-form-item label="下单时间" prop="createtime">
                    <el-date-picker v-model="queryParams.createtime" format="yyyy-MM-dd" type="daterange" start-placeholder="开始时间" end-placeholder="结束时间" style="width: 240px"></el-date-picker>
                </el-form-item>
                <el-form-item label=" ">
                    <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
                    <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class="card">
          <el-row :gutter="10" class="mb8">
                <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
            </el-row>
            <el-table v-loading="loading" :data="tableData" border script row-key="rowKey" show-summary :tree-props="{ children: 'children', hasChildren: 'hasChildren' }">
                <el-table-column label="店铺" prop="shop_name" min-width="140"></el-table-column>
                <el-table-column label="总订单数" prop="OrderTotal" min-width="140"></el-table-column>
                <el-table-column label="售后订单数" prop="OrderFeedbackTotal" min-width="140"></el-table-column>
                <el-table-column label="售后率" prop="proportion" min-width="140"></el-table-column>
                <el-table-column label="SPU" prop="spu" min-width="140"></el-table-column>
            </el-table>
        </div>
    </div>
</template>

<script>
import { queryStoreFeedbackList } from '@/api/order'
import { getShopList } from '@/api/shop'
import { parseTime } from '@/utils/quickadmin'
export default {
    name: 'ProductFeedbackList',
    data() {
        return {
            // 遮罩层
            loading: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 表格数据
            tableData: [],
            // 查询参数
            queryParams: {
                order_id: undefined,
                spu: undefined,
                tag_source: undefined,
                tag_campaign: undefined,
                createtime: [],
                keyword: undefined,
            },
            pageInfo: {
                page: 1,
                limit: 10,
            },
            dict: {
                shopList: [],
            }
        }
    },
    async created() {
        this.loading = true
        try {
            const result = await getShopList()
            this.dict.shopList = result?.data?.list ?? []
        } catch (error) {
            this.loading = false
            console.log(error)
        }
        this.getList()
    },
    methods: {
        //列表
        getList() {
            this.loading = true
            const qyparams = {
                ...this.pageInfo,
                ...this.queryParams,
            }
            if (qyparams.createtime?.length == 2) {
                qyparams.createtime = [parseTime(qyparams.createtime[0], 'y-m-d'), parseTime(qyparams.createtime[1], 'y-m-d')]
            }
            queryStoreFeedbackList(qyparams)
                .then(response => {
                    this.tableData = response.data.list
                    // this.tableData = response.data.map((item, index) => {
                    //     item.rowKey = `${item.shop_id}--${index}`
                    //     if (item.children) {
                    //         item.children.map((pre, i) => {
                    //             pre.rowKey = `${ item.shop_id}--${index}--${i}`
                    //         })
                    //     }
                    //     return { ...item }
                    // })
                    // this.total = response.data?.total ?? 0
                })
                .finally(() => {
                    this.loading = false
                })
        },
        // 搜索按钮操作
        handleQuery() {
            this.pageInfo.page = 1
            this.getList()
        },

        // 重置按钮操作
        resetQuery() {
            this.resetForm('queryForm')

            this.handleQuery()
        },
    },
}
</script>

<style></style>
